package cn.ddm.hrm.controller;

import cn.ddm.hrm.doc.CourseDoc;
import cn.ddm.hrm.query.CourseDocQuery;
import cn.ddm.hrm.repository.CourseElasticsearchRepository;
import cn.ddm.hrm.service.ICourseDocService;
import cn.ddm.hrm.util.AjaxResult;
import cn.ddm.hrm.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/courseDoc")
public class ESController {

    @Autowired
    private CourseElasticsearchRepository repository;

    @Autowired
    private ICourseDocService courseDocService;

    /**
     * 批量添加
     * @param courseDocs
     * @return
     */
    @PostMapping("/add")
    @PreAuthorize("hasAnyAuthority('courseDoc:batchAdd')")
    public AjaxResult batchAdd(@RequestBody List<CourseDoc> courseDocs){
        courseDocService.batchAdd(courseDocs);
        return AjaxResult.me();
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @PostMapping("/del")
    @PreAuthorize("hasAnyAuthority('courseDoc:batchDel')")
    public AjaxResult batchDel(@RequestBody List<Long> ids){
        courseDocService.batchDel(ids);
        return AjaxResult.me();
    }

    /**
     * 查询
     * @param courseDocQuery
     * @return
     */
    @PostMapping("/queryCourse")
    public AjaxResult queryCourse(@RequestBody CourseDocQuery courseDocQuery){
        PageList<CourseDoc> pageList = courseDocService.queryPageData(courseDocQuery);
        return AjaxResult.me().setResultObj(pageList);
    }
}
